Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
ownership.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Roc authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_core/ownership.h
10//! @brief Ownership policies.
11
12#ifndef ROC_CORE_OWNERSHIP_H_
13#define ROC_CORE_OWNERSHIP_H_
14
15namespace roc {
16namespace core {
17
18template <class T, template <class TT> class Ownership> class SharedPtr;
19
20//! Reference countable object ownership.
21template <class T> struct RefCntOwnership {
22 //! Pointer type returned from intrusive containers.
23 //! @remarks
24 //! Container should return smart pointers instead of raw pointers since
25 //! it can call decref() on returned object later.
27
28 //! Acquire ownership.
29 static void acquire(T& object) {
30 object.incref();
31 }
32
33 //! Release ownership.
34 static void release(T& object) {
35 object.decref();
36 }
37};
38
39//! No ownership.
40template <class T> struct NoOwnership {
41 //! Pointer type returned from intrusive containers.
42 //! @remarks
43 //! It's safe to return raw pointer since container will never free objects.
44 typedef T* Pointer;
45
46 //! Acquire ownership.
47 static void acquire(T&) {
48 }
49
50 //! Release ownership.
51 static void release(T&) {
52 }
53};
54
55} // namespace core
56} // namespace roc
57
58#endif // ROC_CORE_OWNERSHIP_H_
Shared ownership intrusive pointer.
Definition: shared_ptr.h:28
Root namespace.
No ownership.
Definition: ownership.h:40
static void acquire(T &)
Acquire ownership.
Definition: ownership.h:47
static void release(T &)
Release ownership.
Definition: ownership.h:51
T * Pointer
Pointer type returned from intrusive containers.
Definition: ownership.h:44
Reference countable object ownership.
Definition: ownership.h:21
SharedPtr< T, core::RefCntOwnership > Pointer
Pointer type returned from intrusive containers.
Definition: ownership.h:26
static void release(T &object)
Release ownership.
Definition: ownership.h:34
static void acquire(T &object)
Acquire ownership.
Definition: ownership.h:29